<?php 



//创建核心类
class Hd{
	
	public static function show(){
		self::_setConst();
	  if(!is_dir("Application")){
		
		self::_makeDir();
		self::_copyFile();		
	  }	
	self::_loadCore();	
	
//	执行应用类	
		\Hdphp\Library\App::show();
	}
	
	//载入核心文件类文件
	
	private static function _loadCore(){
			$path="HDPHP/Library/";
		$files = array(
			"{$path}Functions.php",
			"HDPHP/Org/Smarty/Smarty.class.php",
			"{$path}SmartyView.class.php",
		    "{$path}App.class.php",
			"{$path}Controller.class.php",
			
			
		);
		foreach ($files as  $value) {
			require $value;
//			echo $value."载入成功";
		}
		
		
	}
	
	//	定义AJAX常量判断AJAX动作
	private static function _setConst(){
		//定义是否是post请求
		define('IS_POST', ($_SERVER['REQUEST_METHOD']=='POST')?true :false);
		//定义是否是异步ajax请求    
		if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest')
		{
			define('IS_AJAX', true);		
		}else{
			define('IS_AJAX',false);			
		}	
	}
	
	
	
	//复制文件到相应的目录
	private static function _copyfile(){
//		定义一个路径
		$Path = 'Hdphp/Common/';
		//拷贝Hd框架配置文件到用户应用文件夹
		copy($Path."config.php", "Application/Common/Conf/config.php");
		copy($Path."config.php", "Application/Home/Conf/config.php");
		copy($Path."success.php", "Public/success.php");
		copy($Path."error.php", "Public/error.php");
		copy($Path."IndexController.class.php", "Application/Home/Controller/IndexController.class.php");
		copy($Path."index.php", "Application/Home/View/Index/index.php");		
	}
	
	
	
	//创建文件夹目录
	private  static function _makedir(){
	//把要创建的文件夹路径存入一个数组	
		
	$dir =array(
	'Application',
	'Application/Common',
	'Application/Common/Conf',
	'Application/Home',
	'Application/Home/Conf',
	'Application/Home/Controller',
	'Application/Home/View',
	'Application/Home/View/Index',
	'Public',
	'Application/Runtime/Compile',
	'Application/Runtime/Cache'
	);	
	//循环这个数组进行创建	
	foreach ($dir as $value){
		is_dir($value)||mkdir($value,0777,true);
		}	
	}	
 }
Hd::show();
